<?php
require('includes/model.php');
require('includes/default.php');

$query = new XA_Query($table_name);

if (!empty($model['list']['view_class'])) {
	$listview = new $model['list']['view_class'] ($query);
} else {
	$listview = new XA_ListView_Table($query);
}

$listview->page = xa_in::nat($_GET['page'], 1);
$listview->pk_list = xa::table($table_name)->primary_key_list;
$listview->base_param_list = array('action' => 'list', 'model' => $table_name);

if (file_exists($fname = MODULE_PATH.'model/'.$table_name.'_list.php')) {
	include($fname);
}

if (!$listview->table->field_list) {
	$listview->table->addFieldList($model['label_list']);
}

if (!$listview->option_list) {
	$listview->addOption('edit', 'Edycja', array('action' => 'edit', 'model' => $table_name));
}

//xa::log('list', array('model' => $table_name, 'page' => $listview->page));

$page->title = $model['name'].' - Str. '.$listview->page.(defined('MODULE_NAME') ? ' - '.MODULE_NAME : '').SITE_NAME;
$page->content['listview'] = $listview;
$page->content['table_name'] = $table_name;

$page->template = 'list';
echo $page->out();
